home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0493 / WOPENFIL.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-16  |  4KB  |  124 lines

  1. ─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 284 of 354                                                               
  3. From : Mark Lewis                          1:3634/12.0          14 Apr 93  17:07 
  4. To   : Matt Alberts                        1:2210/7956.0                         
  5. Subj : Too Many Open Files..                                                  
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  > But it errors out (number 4: too many open files) when it really
  8.  > gets into the middle of it.. It works but cannot complete the job..
  9.  > IS there anything I can do to stop this..?
  10.  
  11. there are a couple of ways to handle this...
  12.  
  13. 1. increase your FILES= entry in your CONFIG.SYS -=B-)
  14.  
  15. 2. trap for the error 4 and handle it in one of the following ways...
  16.  
  17.   a. use bits to track open files.
  18.        ie: as you open each file, toggle a bit in a var on for
  19.            =THAT= file. when you get the error 4, close a file,
  20.            toggle it's bit off, open the one you are trying to
  21.            write to and toggle it's bit on.
  22.      keep doing this until the job is done. this method really takes
  23.      a lot more work but you will be able to handle most situations
  24.      where there are not enough file handles to go around.
  25.  
  26.   b. close all open files, clean up, log the error, go home.
  27.  
  28. 3. this one is like 2a... you know how many files you'll need open at one time,
  29. so you can use something like the following routine to see how many are
  30. available. once you know how many are available, you can then decide whether to
  31. abort before the error has a chance to happen, continue on in a modified
  32. operation that doesn't open all the files at once, or do another procedure like
  33. 2a...
  34.  
  35. the following routine (posted in here back in 1991 [hi mike!]) prints the open 
  36. files. i would probably modify it to be a FUNCTION instead of a procedure like 
  37. it is now and also remove the printing part. then you could do something
  38. like...
  39.  
  40. {read CONFIG.SYS to get FILES= number into FILES_IN_CONFIG}
  41. if (FILES_IN_CONFIG - Number_Of_Open_Files) < Number_Open_Files_Needed
  42.   then begin
  43.          writeln('not enough file handles to work with!');
  44.          writeln('please adjust FILES entry in CONFIG.SYS');
  45.          halt; end;
  46.  
  47. there may be another way but this is what i came up with real quickly...
  48.  
  49. {
  50. (244)   Sun 20 Oct 91  1:56p
  51. By: mike janke
  52. To: Michael Reece
  53. Re: files open
  54. ----------------------------------------------------------------------
  55.  > Is there any way to list, and even possibly close, all
  56.  > files currently open (ie in an exitproc)?
  57.  
  58. The following code will list (in readable text form) all open files
  59. (including CON, PRN, etc.).  I don't recall where I got this..
  60. might have been right here in the Pascal conference.
  61.  
  62. As for closing, I don't know of a simple way like BASIC's global
  63. "CLOSE" :-).
  64.  
  65.   -mike
  66.  
  67. {---------------------------------------------------}
  68.  
  69. Procedure WriteOpenFiles;
  70. type
  71.   openfilerec = record
  72.     numtimes : word;
  73.     junk1 : array[2..$1f] of byte;
  74.     filename : array[$20..$2a] of char;
  75.     junk2 : array[$2b..$34] of byte;
  76.   end;
  77.  
  78.   filelistptr = ^filelistrec;
  79.   filelistrec = record
  80.     next : filelistptr;
  81.     numfiles : word;
  82.     files : array[1..1] of openfilerec;
  83.   end;
  84.  
  85. var
  86.   r : registers;
  87.   list : filelistptr;
  88.   i : word;
  89.  
  90. begin
  91.   if lo(dosversion) <> 3 then
  92.    exit;
  93.   with r do
  94.   begin
  95.     ah := $52;
  96.     msdos(r);                {Get the list of lists in ES:BX}
  97.     list := Pointer (MemL[es:bx+4]);    {Get the first open file list }
  98.     while ofs(list^) <> $FFFF do
  99.     begin
  100.       with list^ do
  101.         for i:=1 to numfiles do   { Print each of its files }
  102.           with files[i] do
  103.             if numtimes > 0 then  { but only if they're open }
  104.               writeln(filename);
  105.       list := list^.next;         { Go to the next file list }
  106.     end;
  107.   end;
  108. end; {procedure WriteOpenFiles}
  109.  
  110.  
  111. this will definitly need modification... as written, it will only work with DOS
  112. 3.xx... also, don't forget to account for CON, PRN, and the others like it
  113. mentions in the quoted text...
  114.  
  115. you might be able to get away with checking LIST^.NUMFILES instead of doing the
  116. while loop and incrementing a counter. i don't know right now and can't try it 
  117. to see... have fun and play with it...
  118.  
  119. )\/(ark
  120.  
  121. --- FastEcho 1.25
  122.  * Origin:  (1:3634/12)
  123.  
  124.